﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using BUS;  

namespace OnlineDigitalCameraWebsite.Admin
{
    public partial class OrderList_Detail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                string id = Request.QueryString["id"].ToString();

                lblTieuDe.Text = "Cập Nhật Orders";
                lblTieuDe.DataBind();
                lblTieuDe.DataBind();
                LoadThongTin(id);

            }
        }
        OrdersBUS acBUS = new OrdersBUS();
        private void LoadThongTin(string id)
        {
            int idma = int.Parse(id);
            Order tt = new Order();
            tt = acBUS.GetById(idma);
            txtName.Text = tt.Names;
            txtDiaChi.Text = tt.Addresses;
            txtDienThoai.Text = tt.Phone;
            txtNgay.Text = tt.Dates.ToString();
            txtUserID.Text = "UserName: " + tt.User.userAccount + " .Họ tên: " + tt.User.userName;
            ddlStatus.SelectedValue = tt.ordersStatus.ToString();

            //load chi tiet
            OrdersProductDetailBUS bus = new OrdersProductDetailBUS();
            gvDS.DataSource = bus.GetListByOrderId(idma);
            gvDS.DataBind();
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                string id = Request.QueryString["id"].ToString();

                Order a = new Order();
                int idma = int.Parse(Request.QueryString["id"].ToString());
                a = acBUS.GetById(idma);
                a.Names = txtName.Text;  
                a.Addresses = txtDiaChi.Text;
                a.Phone = txtDienThoai.Text;

                a.ordersStatus = bool.Parse(ddlStatus.SelectedValue.ToString());
                acBUS.Edit(a);
                lbThongBao.Text = "Cập nhật thành công";
                lbThongBao.Visible = true;
                LoadThongTin(id);

            }
            catch (Exception ex)
            {
                lbThongBao.Text = "Lỗi: " + ex.Message;
                lbThongBao.Visible = true;
            }
        }
    }
}